#pragma once
#include <string>
#include <iostream>
#include <map>

namespace krryn{
namespace view{
    class canvas;

	class image_file;
	class image_file_manager{
	public:
		canvas *load(const std::string &a_Filename);
		void store(const std::string &a_Filename, canvas *a_Canvas);
		void register_image_file(const std::string &a_Extension, image_file *a_ImageFile);

		static image_file_manager *get_instance();
	private:
		image_file *find_type(const std::string &a_Filename);

		image_file_manager();
		std::map<std::string, image_file*> m_ImageFiles;
		static image_file_manager *m_Instance;
	};

    class image_file{
    public:
		virtual canvas *load(std::istream &a_InputStream) const = 0;
		virtual void store(std::ostream &a_OutputStream, canvas *a_Canvas) const = 0;
        virtual ~image_file() {}
    };
    
    class image_file_tga : public image_file{
    public:
        virtual canvas *load(std::istream &a_InputStream) const;
        virtual void store(std::ostream &a_OutputStream, canvas *a_Canvas) const;
    private:
        canvas *read_image(unsigned char *a_Data, int a_Width, 
			int a_Height, int a_Depth, bool a_IsTopLeft) const;
    };
    
    class image_file_bmp : public image_file{
    public:
        virtual canvas *load(std::istream &a_InputStream) const;
        virtual void store(std::ostream &a_OutputStream, canvas *a_Canvas) const;
    };
}
}
